﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using IAC_2013.com.iac.util;
using IAC_2013.com.iac.form;

namespace IAC_2013.com.iac.action
{
    class InvoiceInAction
    {
        static SqlConnection conn = new SqlConnection(DBUtils.CONNECTION_STRING);
        static SqlCommand cmd;
        static SqlDataAdapter da;
        static DataTable tb;

        public Boolean addInvoiceIn(InvoiceInForm frm)
        {
            try
            {
                String sql = "INSERT INTO ";
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        /*
         * fill du lieu vao datagridview 
         */ 
        public static DataTable list_Product()
        {
            tb = new DataTable();
            String sql = "select sp.ma_sp, sp.id_sp ";
            sql += " from sp_san_pham sp ";
            sql += " join sp_loai_san_pham l on sp.id_lsp = l.id_lsp ";
            sql += " join dv_don_vi dv on sp.id_dv = dv.id_dv ";

            cmd = new SqlCommand(sql, conn);
            conn.Open();
            da = new SqlDataAdapter(cmd);
            da.Fill(tb);
            conn.Close();

            return tb;
        }

        /*
         * ham xu ly khi chon san pham combox trong grdview product
         */
        public static DataTable getProduct(int productId)
        {
            tb = new DataTable();
            String sql = "select l.ten_loai_sp, sp.ten_sp, dv.ten_dv, sp.quy_cach_sp, sp.kich_thuoc_sp ";
            sql += " from sp_san_pham sp ";
            sql += " join sp_loai_san_pham l on sp.id_lsp = l.id_lsp ";
            sql += " join dv_don_vi dv on sp.id_dv = dv.id_dv ";
            sql += " where sp.id_sp = " + productId;

            cmd = new SqlCommand(sql, conn);
            conn.Open();
            da = new SqlDataAdapter(cmd);
            da.Fill(tb);
            conn.Close();
            return tb;
        }
    }
}
